**********replication analytic code for estimating effects of paid maternity on post-neonatal mortality***********;
********results provided in "Increased duration of paid maternity leave lowers infant mortality in low- and middle-
income countries: a quasi-experimental study" by Nandi et al., published in PLOS MEDICINE on March 29, 2016*******;


*IMPORT DATASET FOR ANALYSIS OF POST-NEONATAL MORTALITY, NAMED 'INFM_rep_20160601';

libname rep 'X:\'; *insert directory where replication file 'INFM_rep_20160601' is stored;
run;

data pneo_rep;
set rep.INFM_rep_20160601;
run;

proc contents data=pneo_rep varnum short; run;

proc sort data=pneo_rep; by iso3 yearbirth; run;


*WE CONDUCTED A COMPLETE CASE ANALYSIS THAT RESTRICTED ANALYSES TO OBSERVATIONS WITH NONMISSING COVARIATE VALUES;

data pneo_rep; 
set pneo_rep;
if ftem>. and durm>. and pndeath>. and male>. and edumother>. and wq2-wq5>. and urban>. and bthinval24>. 
and age2039>. and age40>. and brdelpro>.; 
run;


*MAIN ANALYSES (Table 5). The following models correspond to models (1)-(3) in table 5: Effects of an increase in paid 
maternity leave, measured by an additional month of paid leave, on the number of post-neonatal deaths per 1000 live births, 
Demographic and Health Surveys, 2000-2007

*model 1: with fixed effects for country and year;

proc surveyreg data=pneo_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model pndeath=durm_lag1 iso3 yearbirth/solution clparm;
weight dnwt;
run;


*Model 2: Model 1 + measured individual, household, and country-level characteristics;

proc surveyreg data=pneo_rep order=freq;
cluster iso3; class iso3 yearbirth;
model pndeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp /solution clparm;
weight dnwt;
run;


*Model 3: Model 2 + per capita total and government health expenditures--these data were unavailable for all 
years for Zimbabwe and observations from Zimbabwe were therefore dropped from Model 3;

proc surveyreg data=pneo_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model pndeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*ANCILLARY ANALYSES;

*Table S2. effect of effect of paid maternity leave on post-neonatal morality on the risk ratio scale;

proc genmod data=pneo_rep descending order=freq;
class iso3 yearbirth;
model pndeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/link=log dist=poisson;
repeated subject=iso3/type=ind; 
weight dnwt;
run;


*Table S3 and Figure S2. Models examining potential non-linearity in the effect of paid maternity leave on post-neonatal morality 
by introducing a quadratic duration of paid leave variable to a fully adjusted model;

proc surveyreg data=pneo_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model pndeath=durm_lag1|durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
store nonlin_pn;
run;

ods graphics on;
proc plm source=nonlin_pn;
effectplot fit (x=durm_lag1);
run;
ods graphics off;


*SENSITIVITY ANALYSES (Table S6). the following models correspond to models (a)-(d) in table S6:

*Model a. measures the effects of an additional month of paid leave in full time equivalent (FTE) units, 
obtained by multiplying the legislated length of leave by the wage replacement rate (therefore this model does 
not additionally control for the wage replacement rate);

proc surveyreg data=pneo_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model pndeath=ftem_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*Model b. unweighted estimates;

proc surveyreg data=pneo_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model pndeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
run;


*Model c. this model added to our primary exposure, the lagged effect of paid maternity leave (t-1), 
parameters representing paid maternity leave in preceding years (t-3, t-2), the survey year (t), 
and subsequent years (t+1, t+2, t+3); 

proc surveyreg data=pneo_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model pndeath=durm_lag3 durm_lag2 durm_lag1 durm durm_lead1 durm_lead2 durm_lead3 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


